﻿# Promote lowborn

shogunate_promote_lowborn_effect = {

	save_scope_as = old_character
	if = {
		limit = {
			is_lowborn = yes
			NOT = {
				any_close_family_member = {
					count = 1
				}
			}
			NOT = {
				any_consort = {
					count = 1
				}
			}
		}
		if = {
			limit = {
				exists = scope:old_character.location
			}
			if = {
				limit = {
					exists = scope:old_character.employer
				}
				create_character = {
					template_character = scope:old_character
					dynasty  = generate
					gender   = scope:old_character
					age      = scope:old_character.age
					location = scope:old_character.location
					employer = scope:old_character.employer
					save_scope_as = new_character
				}
			}
			else = {
				create_character = {
					template_character = scope:old_character
					dynasty  = generate
					gender   = scope:old_character
					age      = scope:old_character.age
					location = scope:old_character.location
					save_scope_as = new_character
				}
			}
		}
		else = {
			create_character = {
				template_character = scope:old_character
				dynasty  = generate
				gender   = scope:old_character
				age      = scope:old_character.age
				save_scope_as = new_character
			}
		}
		scope:new_character = {
			clear_traits = yes
			copy_traits  = scope:old_character
			shogunate_promote_lowborn_copy_skill_effect = yes
			change_first_name = { template_character = scope:old_character }
		}
		death = { death_reason = death_vanished }
	}

}


# Promote lowborn courtiers generated by gaining a title

shogunate_promote_lowborn_courtiers_effect = {

	if = {
		limit = {
			NOT = { exists = scope:title }		# only if they had no title before
		}
		every_courtier_or_guest = {
			shogunate_promote_lowborn_effect = yes
		}
	}

}


# Copy all skills from the old character to the new character

shogunate_promote_lowborn_copy_skill_effect = {

	scope:old_character = {
		force_character_skill_recalculation = yes
	}
	scope:new_character = {
		force_character_skill_recalculation = yes
	}

	shogunate_promote_lowborn_copy_each_skill_effect = { TYPE = diplomacy }
	shogunate_promote_lowborn_copy_each_skill_effect = { TYPE = martial }
	shogunate_promote_lowborn_copy_each_skill_effect = { TYPE = stewardship }
	shogunate_promote_lowborn_copy_each_skill_effect = { TYPE = intrigue }
	shogunate_promote_lowborn_copy_each_skill_effect = { TYPE = learning }
	shogunate_promote_lowborn_copy_each_skill_effect = { TYPE = prowess }

	scope:new_character = {
		force_character_skill_recalculation = yes
	}

}


# Copy each skill from the old character to the new character

shogunate_promote_lowborn_copy_each_skill_effect = {

	set_variable = {
		name = difference
		value = scope:old_character.$TYPE$
	}
	change_variable = {
		name = difference
		subtract = scope:new_character.$TYPE$
	}
	scope:new_character = {
		add_$TYPE$_skill = var:difference
	}
	remove_variable = difference

}
